package net.imain.cloud;

import net.imain.cloud.annotations.MyAnnotations;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;

/**
 * 服务消费者，消费隔壁的user服务
 *
 * @author uncle
 */
@EnableDiscoveryClient
@SpringBootApplication
/* 覆盖 SpringBootApplication 中的 ComponentScan */
@ComponentScan(excludeFilters = {@ComponentScan.Filter(value = MyAnnotations.class)})
/* 这个名字一定要是Eureka Server中已经注册的名字。 */
@RibbonClient(name = "service-user", configuration = RibbonConfig.class)
public class MovieRibbonApplication {

	/**
	 * 生成一个spring封装好的http请求客户端对象
	 *
	 * @return
	 */
	@Bean
	@LoadBalanced // 此注解让 restTemplate 具备负载均衡的能力
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

	/**
	 * 课程要点：
	 * 		1.如何不硬编码的调用USER微服务的API
	 * 		2.假设有多个节点，如何让MOVIE微服务请求USER微服务的时候做到负载均衡
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		SpringApplication.run(MovieRibbonApplication.class, args);
	}
}
